const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const Resident = require('./Resident');

const HealthRecord = sequelize.define('HealthRecord', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    residentId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: Resident,
            key: 'id'
        }
    },
    recordDate: {
        type: DataTypes.DATE,
        allowNull: false,
        defaultValue: DataTypes.NOW
    },
    symptoms: {
        type: DataTypes.TEXT,
        allowNull: false
    },
    treatment: {
        type: DataTypes.TEXT,
        allowNull: false
    }
}, {
    timestamps: true
});

// 设置关联关系
HealthRecord.belongsTo(Resident, { foreignKey: 'residentId' });
Resident.hasMany(HealthRecord, { foreignKey: 'residentId' });

module.exports = HealthRecord; 